package com.mall.service.impl;

import com.mall.common.utils.Security;
import com.mall.dao.custom.CtCarouselMapper;
import com.mall.entity.Carousel;
import com.mall.service.CarouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

/**
 * @author xyl
 * @date 2021-02-28 14:17
 */
@Service
public class CarouseServiceImpl implements CarouseService {

    @Autowired
    private CtCarouselMapper carouselMapper;

    @Override
    public int add(Carousel carousel) {
        carousel.setCreateBy(Security.getCurrentUserId());
        carousel.setCreateTime(new Date());
        return carouselMapper.insert(carousel);
    }

    @Override
    public int remove(Integer carouselId) {
        return carouselMapper.deleteByPrimaryKey(carouselId);
    }

    @Override
    public int modify(Carousel carousel) {
        carousel.setUpdateBy(Security.getCurrentUserId());
        carousel.setUpdateTime(new Date());
        return carouselMapper.updateByPrimaryKeySelective(carousel);
    }

    @Override
    public int getShowCount() {
        return carouselMapper.selectShowCount();
    }

    @Override
    public List<Carousel> list() {
        return carouselMapper.selectShowList();
    }

    @Override
    public Carousel getCarouseByGoodsId(Integer goodsId) {
        return carouselMapper.selectByGoodsId(goodsId);
    }

    @Override
    public List<Carousel> all() {
        return carouselMapper.selectAll();
    }
}
